/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.ResultSet;
import java.util.ArrayList;
import pojo.ThuongHieu_pojo;
import util.MySQLDataAccessHelper;

/**
 *
 * @author Rocker000
 */
public class ThuongHieu_dao 
{
     public static ThuongHieu_pojo LayThuongHieuTheoMaThuongHieu(String mathuonghieu)
    {
        ThuongHieu_pojo hieu = new ThuongHieu_pojo();
        try
        {
            String sql = "select*from thuonghieu where mathuonghieu='"+mathuonghieu+"'";
            MySQLDataAccessHelper helper = new MySQLDataAccessHelper();
            helper.Open();
            ResultSet rs = helper.ExeCuteQuery(sql);
            while(rs.next())
            {
                
                hieu.setMaThuongHieu(rs.getString("mathuonghieu"));
                hieu.setTenThuongHieu(rs.getString("tenthuonghieu"));
                
            }
            helper.Close();
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());
        }
        return hieu;
    }
    
    public static ArrayList<ThuongHieu_pojo> LayDanhSachTheoDanhMuc(String madanhmuc)
    {
        ArrayList<ThuongHieu_pojo> ds = new ArrayList<ThuongHieu_pojo>();
        String sql="select DISTINCT TenThuongHieu,MaThuongHieu from sieuthidienmay.sanpham,sieuthidienmay.loaisanpham,sieuthidienmay.danhmuc,sieuthidienmay.thuonghieu where danhmuc.madanhmuc='"+madanhmuc +"'and sanpham.maloaisanpham=loaisanpham.maloaisanpham and sanpham.hieu=thuonghieu.mathuonghieu and loaisanpham.madanhmuc=danhmuc.madanhmuc ";
        try
        {
            MySQLDataAccessHelper helper = new MySQLDataAccessHelper();
            helper.Open();
            ResultSet rs = helper.ExeCuteQuery(sql);
            while(rs.next())
            {
                ThuongHieu_pojo temp = new ThuongHieu_pojo();
                temp.setMaThuongHieu(rs.getString("mathuonghieu"));
                temp.setTenThuongHieu(rs.getString("tenthuonghieu"));
                ds.add(temp);
            }
            helper.Close();
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());
        }
        return ds;
    }
    
    public static ArrayList<ThuongHieu_pojo> LayDanhSachTheoLoaiSanPham(String maloaisanpham)
    {
        ArrayList<ThuongHieu_pojo> ds = new ArrayList<ThuongHieu_pojo>();
        String sql="select distinct thuonghieu.tenthuonghieu,thuonghieu.mathuonghieu from sanpham,loaisanpham,thuonghieu where loaisanpham.maloaisanpham ='"+maloaisanpham+"'and sanpham.maloaisanpham=loaisanpham.maloaisanpham and sanpham.hieu=thuonghieu.mathuonghieu  ";
        try
        {
            MySQLDataAccessHelper helper = new MySQLDataAccessHelper();
            helper.Open();
            ResultSet rs = helper.ExeCuteQuery(sql);
            while(rs.next())
            {
                ThuongHieu_pojo temp = new ThuongHieu_pojo();
                temp.setMaThuongHieu(rs.getString("mathuonghieu"));
                temp.setTenThuongHieu(rs.getString("tenthuonghieu"));
                ds.add(temp);
            }
            helper.Close();
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());
        }
        return ds;
    }
    public static ArrayList<ThuongHieu_pojo> LayToanBo()
    {
        ArrayList<ThuongHieu_pojo> ds = new ArrayList<ThuongHieu_pojo>();
        String sql="select*from thuonghieu";
        try
        {
            MySQLDataAccessHelper helper = new MySQLDataAccessHelper();
            helper.Open();
            ResultSet rs = helper.ExeCuteQuery(sql);
            while(rs.next())
            {
                ThuongHieu_pojo temp = new ThuongHieu_pojo();
                temp.setMaThuongHieu(rs.getString("mathuonghieu"));
                temp.setTenThuongHieu(rs.getString("tenthuonghieu"));
                ds.add(temp);
            }
            helper.Close();
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());
        }
        return ds;
    }
    
}
